package com.shw.pclient.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @author HAHA
 * 
 */
public class StringTools {

	public static String getDateTimeSecond() {
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String result = sdf.format(calendar.getTime());
		return result;
	}

	public static String getFormatDateTimeSecond() {
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String result = sdf.format(calendar.getTime());
		return result;
	}

	public static String gets(byte[] bs){
		String strRead = new String(bs);
		strRead = String.copyValueOf(strRead.toCharArray(), 0, bs.length); 
		return strRead;
	}
	public static String getFormatDate(String s) {
		String result = s.substring(0, 4) + "-" + s.substring(4, 6) + "-"
				+ s.substring(6, 8) + " " + s.substring(8, 10) + ":"
				+ s.substring(10, 12) + ":" + s.substring(12, 14);
		return result;
	}

	public static String toHexString(String s) {
		String s4 = Integer.toHexString(Integer.valueOf(s));
		s4 = leftAdding(s4, "0", 2);
		return s4;
	}

	public static String getHexDateTimeSecond() {
		String result = getDateTimeSecond();
		result = toHexString(result.substring(2, 4))
				+ toHexString(result.substring(4, 6))
				+ toHexString(result.substring(6, 8))
				+ toHexString(result.substring(8, 10))
				+ toHexString(result.substring(10, 12))
				+ toHexString(result.substring(12, 14));
		return result;
	}

	public static String getFormatLALO(double lalo) {
		String result = String.valueOf(lalo);
		if (result.length() > 8) {
			result = result.substring(0, 8);
		}
		result=leftAdding(result, "0", 8);
		return result;
	}

	public static String toStringHex2(String s) {
		byte[] baKeyword = new byte[s.length() / 2];
		for (int i = 0; i < baKeyword.length; i++) {
			try {
				baKeyword[i] = (byte) (0xff & Integer.parseInt(
						s.substring(i * 2, i * 2 + 2), 16));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		try {
			s = new String(baKeyword, "utf-8");// UTF-16le:Not
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		return s;
	}

	public static String leftAdding(String str, String info, int length) {
		int size = length - str.length();
		StringBuffer result = new StringBuffer("");
		for (int i = 0; i < size; i++) {
			result.append(info);
		}
		result.append(str);
		return result.toString();
	}

	public static void main(String args[]) {

		System.out.println(StringTools.getDateTimeSecond());
	}
}